﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Web;
using System.Text.RegularExpressions;
using System.Web;

namespace WeatherAppService
{
    public static class Validator
    {
        public static bool IsValidAuthHead()
        {
            WebOperationContext ctx = WebOperationContext.Current;
            string authStr = ctx.IncomingRequest.Headers[HttpRequestHeader.Authorization];

            if (authStr == null || authStr.Length == 0)
            {
                // No credentials; anonymous request               
                return false;
            }

            authStr = authStr.Trim();
            if (authStr.IndexOf("Basic", 0) != 0)
            {
                // header is not correct                
                return false;
            }
            return true;
        }

        public static bool IsValidEmail(string strIn)
        {
            // Return true if strIn is in valid e-mail format.
            return Regex.IsMatch(strIn,
                    @"^(?("")(""[^""]+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
                    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");
        }

        public static bool IsValidPass(string p)
        {
            if (p.Length < 6)
                return false;
            return true;
        }
    }
}